-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep Vec::capacity
const
#498
Keep Vec::capacity
const
#498
Conversation
In 0.8.0 it was const, but this was removed in rust-embedded#486 The other container types did not make the `capacity` method const, and therefore can kept with the normal name and the generic implementation.
94b0ea5
to
27bff4a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh oops, nice find! thanks
@@ -408,7 +415,7 @@ impl<T, S: Storage> VecInner<T, S> { | |||
} | |||
|
|||
/// Returns the maximum number of elements the vector can hold. | |||
pub fn capacity(&self) -> usize { | |||
pub fn storage_capacity(&self) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sosthene-nitrokey, why can't this use the same name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storage_capacity
applies to VecInner<T, S>
, for any storage
capacity
applies to VecInner<T, OwnedStorage<N>>
aka Vec<T, N>
only.
so for Vec<T, N>
both apply, so it'd give ambiguity errors if the user wrote vec.capacity()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so for Vec<T, N> both apply, so it'd give ambiguity errors if the user wrote vec.capacity()
It wouldn't even allow getting to that point. The compiler would complain about duplicate definitions with the same name.
We could implement fn capacity
on Vec
and VecView
independently, but then it would make it unusable in a generic context over the storage.
In 0.8.0 it was const, but this was removed in #486, which would be an unexpected breaking change.
The other container types did not make the
capacity
method const, and therefore can kept with the normal name and the generic implementation.No need for changelog for this change, since it affects b previous PR that has not been released.